import * as actionType from './constants';

import { getTopBanners, getHotRecommends } from '@/services/recommend';

// action
const changeTopBannerAction = (res) => ({
  type: actionType.CHANGE_TOP_BANNERS,
  topBanners: res.banners
});

const changeHotRecommendsAction = (res) => ({
  type: actionType.CHANGE_HOT_RECOMMRNDS,
  hotRecommends: res.result
});

// getData
export const getTopBannerAction = (dispatch) => {
  return getTopBanners().then((res) => {
    dispatch(changeTopBannerAction(res));
  });
};


export const getHotRecommendAction = (limit) => {
  return dispatch =>{
    getHotRecommends(limit).then(res=>{
      dispatch(changeHotRecommendsAction(res));
    })
  }
};